package client;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

public class World {

	private List<Area> levels;

	public World() {
		levels = new ArrayList<Area>();
	}

	public Area getArea(int x, int y) {
		Area a = null;
		for (Area area : levels) {
			if (area.getWorldX() == x && area.getWorldY() == y) {
				a = area;
			}
		}
		if (a != null) {
			return a;
		} else {
			return null;
		}
	}

	public void addArea(Area a) {
		boolean overlap = false;
		for (Area area : levels) {
			if (area.getWorldX() == a.getWorldX()
					&& area.getWorldY() == a.getWorldY()) {
				area = a;
				overlap = true;
			}
		}
		if (overlap == false) {
			levels.add(a);
		}
	}
	
	public void drawWorldMap(Graphics g, Player p){
		int size = 50;
		int xoffset = 175;
		int yoffset = 175;
		for (Area area : levels) {
			if(p.getCurrentArea().getWorldX()==area.getWorldX() && p.getCurrentArea().getWorldY()==area.getWorldY()){
				g.setColor(Color.GREEN);
				g.fillRect(area.getWorldX()*size+xoffset, area.getWorldY()*size+yoffset, size, size);
			} else {
				g.setColor(Color.GRAY);
				g.fillRect(area.getWorldX()*size+xoffset, area.getWorldY()*size+yoffset, size, size);
			}
			g.setColor(Color.BLACK);
			g.drawRect(area.getWorldX()*size+xoffset, area.getWorldY()*size+yoffset, size, size);
		}
	}

}
